package org.winexpress

/**
 *
 * @author Swee Zhi
 */
class PasswordManagement {
    
    def generatePassword() {
        def pool = ['a'..'z','A'..'Z',0..9,'_'].flatten()
        Random rand = new Random(System.currentTimeMillis())

        def passChars = (0..10).collect { pool[rand.nextInt(pool.size())] }
        def password = passChars.join()
        
        println 'Generated Password Is (please do not forget this): ' + password
        
        return password
    }
    
    def encodePassword(userPassword) {
        PasswordCodec pwd = new PasswordCodec()
        def encodedPassword = pwd.encode(userPassword)
        
        println 'Encoded Password to be stored is: ' + encodedPassword
        
        return encodedPassword
    }
}

